//
//  RAPVisitorViewController.swift
//  COPYCAT-Weibo
//
//  Created by 闫萌 on 12/28/15.
//  Copyright © 2015 RendezvousAuParadis. All rights reserved.
//

/*
这是一个继承自UITableViewControlle的base class
*/

import UIKit

class RAPVisitorViewController: UITableViewController, RAPVisitorViewDelegate {
    
    /**
    是否已经登录
    */
    var isLogin: Bool = RAPAccountViewModel.sharedViewModel.loginCheck()
    
    lazy var visitorView: RAPVisitorView = RAPVisitorView()

    override func loadView() {
        isLogin ? super.loadView() : {
            visitorView = RAPVisitorView()
            view = visitorView
            }()
    }
    
    // MARK: - RAPVisitorViewDelegate
    func loginButtonClicked() {
        RAPLog("登录按钮点击")
        presentViewController(RAPMainNavigationController(rootViewController: RAPOAuthViewController()), animated: true) { () -> Void in
            
        }
    }
    
    func signupButtonClicked() {
        RAPLog("注册按钮点击")
    }
    
    override func viewDidLoad() {
        // 如果尚未登录
        if !isLogin {
            // 设置代理
            visitorView.delegate = self
            // 设置导航栏按钮
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginButtonClicked")
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "signupButtonClicked")
        }
    }

}
